/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import hibernatemodelo.*;
import java.util.Date;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 * Clase con el panel de usuario
 *
 * @author Mª Luz García Rodríguez
 * @author Luis Massó Saiz
 */
public class JIntPanelUsuario extends javax.swing.JInternalFrame {

    MdiPrueba padre;

    public MdiPrueba getPadre() {
        return padre;
    }

    public void setPadre(MdiPrueba padre) {
        this.padre = padre;
    }

    /**
     * Constructor
     */
    public JIntPanelUsuario() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jCbContactoAmigoNuevo = new javax.swing.JComboBox();
        jLContactoAmigoNuevo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLiContactoLista = new javax.swing.JList();
        jBAmigosEliminar = new javax.swing.JButton();
        jBanyadirAmigo = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLContactoNombre = new javax.swing.JLabel();
        jLContactoTelefono = new javax.swing.JLabel();
        jLContactoMail = new javax.swing.JLabel();
        jTNombre = new javax.swing.JTextField();
        jTTelefono = new javax.swing.JTextField();
        jTEmail = new javax.swing.JTextField();
        jBUsuarioModificar = new javax.swing.JButton();
        jLContactoMail1 = new javax.swing.JLabel();
        jContra = new javax.swing.JPasswordField();
        jBGuardarUsuario = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jBUsuarioEventoNuevo = new javax.swing.JButton();
        jBEventosEliminar = new javax.swing.JButton();
        jBEventosDetalles = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jLiEventosLista = new javax.swing.JList();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jLiEventosInvitado = new javax.swing.JList();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setResizable(true);
        setTitle("Panel de usuario");
        setName(""); // NOI18N
        setPreferredSize(new java.awt.Dimension(920, 694));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Amigos"));
        jPanel2.setMinimumSize(new java.awt.Dimension(409, 637));

        jCbContactoAmigoNuevo.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N

        jLContactoAmigoNuevo.setText("Añadir Amigo");

        jScrollPane1.setViewportView(jLiContactoLista);

        jBAmigosEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/delete.png"))); // NOI18N
        jBAmigosEliminar.setText("Eliminar");
        jBAmigosEliminar.setPreferredSize(new java.awt.Dimension(130, 50));
        jBAmigosEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAmigosEliminarActionPerformed(evt);
            }
        });

        jBanyadirAmigo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/save.png"))); // NOI18N
        jBanyadirAmigo.setText("Añadir");
        jBanyadirAmigo.setPreferredSize(new java.awt.Dimension(130, 50));
        jBanyadirAmigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBanyadirAmigoActionPerformed(evt);
            }
        });

        jLabel1.setText("Mis amigos");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLContactoAmigoNuevo)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jBAmigosEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                            .addComponent(jBanyadirAmigo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jCbContactoAmigoNuevo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1))
                    .addComponent(jLabel1))
                .addGap(0, 15, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLContactoAmigoNuevo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCbContactoAmigoNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBAmigosEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBanyadirAmigo, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Personales:"));

        jLContactoNombre.setText("Nombre: ");

        jLContactoTelefono.setText("Teléfono");

        jLContactoMail.setText("eMail:");

        jTNombre.setEditable(false);
        jTNombre.setPreferredSize(new java.awt.Dimension(280, 25));

        jTTelefono.setEditable(false);
        jTTelefono.setPreferredSize(new java.awt.Dimension(280, 25));

        jTEmail.setEditable(false);
        jTEmail.setPreferredSize(new java.awt.Dimension(280, 25));

        jBUsuarioModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/file_edit.png"))); // NOI18N
        jBUsuarioModificar.setText("Modificar");
        jBUsuarioModificar.setPreferredSize(new java.awt.Dimension(135, 45));
        jBUsuarioModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBUsuarioModificarActionPerformed(evt);
            }
        });

        jLContactoMail1.setText("Contraseña");

        jContra.setEditable(false);

        jBGuardarUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/save.png"))); // NOI18N
        jBGuardarUsuario.setText("Guardar");
        jBGuardarUsuario.setEnabled(false);
        jBGuardarUsuario.setPreferredSize(new java.awt.Dimension(130, 50));
        jBGuardarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBGuardarUsuarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLContactoNombre)
                            .addComponent(jLContactoTelefono)
                            .addComponent(jLContactoMail)
                            .addComponent(jLContactoMail1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTEmail, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jTTelefono, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jTNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jContra, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jBUsuarioModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBGuardarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(20, 20, 20))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLContactoNombre, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLContactoTelefono, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTTelefono, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLContactoMail, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTEmail, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLContactoMail1)
                    .addComponent(jContra, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBUsuarioModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBGuardarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Eventos"));

        jBUsuarioEventoNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/save.png"))); // NOI18N
        jBUsuarioEventoNuevo.setText("Nuevo");
        jBUsuarioEventoNuevo.setPreferredSize(new java.awt.Dimension(122, 45));
        jBUsuarioEventoNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBUsuarioEventoNuevoActionPerformed(evt);
            }
        });

        jBEventosEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/delete.png"))); // NOI18N
        jBEventosEliminar.setText("Eliminar");
        jBEventosEliminar.setPreferredSize(new java.awt.Dimension(130, 50));
        jBEventosEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEventosEliminarActionPerformed(evt);
            }
        });

        jBEventosDetalles.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/file_edit.png"))); // NOI18N
        jBEventosDetalles.setText("Detalles");
        jBEventosDetalles.setPreferredSize(new java.awt.Dimension(130, 50));
        jBEventosDetalles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEventosDetallesActionPerformed(evt);
            }
        });

        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });

        jScrollPane2.setViewportView(jLiEventosLista);

        jTabbedPane1.addTab("Mis eventos futuros/en curso", jScrollPane2);

        jLiEventosInvitado.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(jLiEventosInvitado);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jTabbedPane1.addTab("Eventos a los que estoy invitado", jPanel5);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jBEventosEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBEventosDetalles, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBUsuarioEventoNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jBEventosEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                    .addComponent(jBEventosDetalles, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                    .addComponent(jBUsuarioEventoNuevo, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Método que se ejecuta cuando se le da al botón de modificar en el panel
     * de datos personales
     *
     * @param evt
     */
    private void jBUsuarioModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBUsuarioModificarActionPerformed
        jTEmail.setEditable(true);
        jTNombre.setEditable(true);
        jTTelefono.setEditable(true);
        jContra.setEditable(true);

        jBUsuarioModificar.setEnabled(false);
        jBGuardarUsuario.setEnabled(true);
    }//GEN-LAST:event_jBUsuarioModificarActionPerformed

    /**
     * Método que se ejecuta cuando se le da al botón guardar del panel de datos
     * personales
     *
     * @param evt
     */
    private void jBGuardarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBGuardarUsuarioActionPerformed

        padre.miContacto.setContrasenya(jContra.getText());
        padre.miContacto.setEmail(jTEmail.getText());
        padre.miContacto.setTelefono(jTTelefono.getText());
        padre.miContacto.setNombre(jTNombre.getText());

        try {
            padre.contactoControlador.edit(padre.miContacto);
            padre.listaContactos = padre.contactoControlador.findContactoEntities();
            JOptionPane.showMessageDialog(null, "Datos actualizados correctamente");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "No se han podido guardar los cambios");
        }

        jTEmail.setEditable(false);
        jTNombre.setEditable(false);
        jTTelefono.setEditable(false);
        jContra.setEditable(false);

        jBUsuarioModificar.setEnabled(true);
        jBGuardarUsuario.setEnabled(false);

    }//GEN-LAST:event_jBGuardarUsuarioActionPerformed

    /**
     * Método que se ejecuta al darle al botón de Evento Nuevo
     *
     * @param evt
     */
    private void jBUsuarioEventoNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBUsuarioEventoNuevoActionPerformed
        // le pasamos -1 para discernir cuando es nuevo y cuando es mostrar evento existente
        padre.mostrarEventosConId(-1);
    }//GEN-LAST:event_jBUsuarioEventoNuevoActionPerformed

    /**
     * Método que se ejecuta al darle al botón de Eliminar Evento
     *
     * @param evt
     */
    private void jBEventosEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEventosEliminarActionPerformed
        Evento ev = (Evento) jLiEventosLista.getSelectedValue();

        if (ev != null) {
            int respuesta = JOptionPane.showConfirmDialog(null,
                    "Realmente desea borrar su eventoa: " + ev.toString(),
                    "Eliminar evento", JOptionPane.YES_NO_OPTION);

            if (respuesta == JOptionPane.YES_OPTION) {
                try {
                    for (Invitar i : ev.getInvitarCollection()) {
                        padre.invitarControlador.destroy(i.getId());
                    }
                    padre.lugarControlador.destroy(ev.getLugar().getId());
                    padre.eventoControlador.destroy(ev.getId());
                    padre.listaEventos = padre.eventoControlador.findEventoEntities();
                    int id = padre.miContacto.getId();
                    padre.miContacto = padre.contactoControlador.findContacto(id);
                    JOptionPane.showMessageDialog(null, "Evento eliminado con éxito");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "No se ha podido eliminar el evento");
                }
                cargarListaEventos();
            }
        }

    }//GEN-LAST:event_jBEventosEliminarActionPerformed

    /**
     * Método que se ejecuta al darle al botón de Añadir amigo
     *
     * @param evt
     */
    private void jBanyadirAmigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBanyadirAmigoActionPerformed

        if (jCbContactoAmigoNuevo.getSelectedIndex() >= 0) {
            Contacto c = (Contacto) jCbContactoAmigoNuevo.getSelectedItem();

            int respuesta = JOptionPane.showConfirmDialog(null,
                    "Realmente desea añadir a su lista de amigos a: " + c.getNombre(),
                    "Añadir amigo", JOptionPane.YES_NO_OPTION);

            if (respuesta == JOptionPane.YES_OPTION) {
                try {
                    Seramigo sa = new Seramigo();
                    sa.setIdamigo1(c);
                    sa.setIdamigo2(padre.miContacto);
                    padre.serAmigoControlador.create(sa);
                    padre.listaAmigos = padre.serAmigoControlador.findSeramigoEntities();
                    int id = padre.miContacto.getId();
                    padre.miContacto = padre.contactoControlador.findContacto(id);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "No se ha podido añadir como amigo");
                }

                cargarComboBoxAmigos();
                cargarListaAmigos();
            }
        }
    }//GEN-LAST:event_jBanyadirAmigoActionPerformed

    /**
     * Método que se ejecuta al darle al botón Eliminar Amigo
     *
     * @param evt
     */
    private void jBAmigosEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAmigosEliminarActionPerformed
        Contacto c = (Contacto) jLiContactoLista.getSelectedValue();

        if (c != null) {
            int respuesta = JOptionPane.showConfirmDialog(null,
                    "Realmente desea borrar de su lista de amigos a: " + c.getNombre(),
                    "Eliminar amigo", JOptionPane.YES_NO_OPTION);

            if (respuesta == JOptionPane.YES_OPTION) {
                try {
                    Seramigo sa = new Seramigo();
                    for (Seramigo s : padre.listaAmigos) {
                        if ((s.getIdamigo1().getId() == padre.miContacto.getId()) && (s.getIdamigo2().getId() == c.getId())) {
                            sa = s;
                        } else if (s.getIdamigo2().getId() == padre.miContacto.getId() && (s.getIdamigo1().getId() == c.getId())) {
                            sa = s;
                        }
                    }
                    padre.serAmigoControlador.destroy(sa.getId());
                    padre.listaAmigos = padre.serAmigoControlador.findSeramigoEntities();
                    int id = padre.miContacto.getId();
                    padre.miContacto = padre.contactoControlador.findContacto(id);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "No se ha podido borrar como amigo");
                }

                cargarComboBoxAmigos();
                cargarListaAmigos();
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe seleccionar un contacto de la lista");
        }
    }//GEN-LAST:event_jBAmigosEliminarActionPerformed

    /**
     * Método que llamará al formulario de crear eventos mostrando el
     * seleccionado en el listbox correcpondiente
     *
     * @param evt
     */
    private void jBEventosDetallesActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jBEventosDetallesActionPerformed
    {//GEN-HEADEREND:event_jBEventosDetallesActionPerformed
        Evento opcion;
        switch (jTabbedPane1.getSelectedIndex()) {
            case 0: //Pestaña Mis Eventos 
                opcion = (Evento) jLiEventosLista.getSelectedValue();
                if (opcion == null) // no hay ninguno seleccinado
                {
                    JOptionPane.showMessageDialog(null, "Seleccione un evento en la lista");
                } else // hay alguno seleccionado
                {
                    padre.mostrarEventos(opcion);
                }
                break;
            case 1: // Pestaña Eventos a los que estoy invitado
                opcion = (Evento) jLiEventosInvitado.getSelectedValue();
                if (opcion == null) // no hay ninguno seleccinado
                {
                    JOptionPane.showMessageDialog(null, "Seleccione un evento en la lista");
                } else // hay alguno seleccionado
                {
                    padre.mostrarEventos(opcion);
                }
                break;
        }

    }//GEN-LAST:event_jBEventosDetallesActionPerformed

    /**
     * Método que se ejecuta al cambiar de pestaña del TabbedPane
     *
     * @param evt
     */
    private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked
        switch (jTabbedPane1.getSelectedIndex()) {
            case 0: //Pestaña Mis Eventos 
                jBEventosEliminar.setVisible(true);
                jBUsuarioEventoNuevo.setVisible(true);
                break;
            case 1: // Pestaña Eventos a los que estoy invitado
                jBEventosEliminar.setVisible(false);
                jBUsuarioEventoNuevo.setVisible(false);
                break;
        }
    }//GEN-LAST:event_jTabbedPane1MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAmigosEliminar;
    private javax.swing.JButton jBEventosDetalles;
    private javax.swing.JButton jBEventosEliminar;
    private javax.swing.JButton jBGuardarUsuario;
    private javax.swing.JButton jBUsuarioEventoNuevo;
    private javax.swing.JButton jBUsuarioModificar;
    private javax.swing.JButton jBanyadirAmigo;
    private javax.swing.JComboBox jCbContactoAmigoNuevo;
    private javax.swing.JPasswordField jContra;
    private javax.swing.JLabel jLContactoAmigoNuevo;
    private javax.swing.JLabel jLContactoMail;
    private javax.swing.JLabel jLContactoMail1;
    private javax.swing.JLabel jLContactoNombre;
    private javax.swing.JLabel jLContactoTelefono;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jLiContactoLista;
    private javax.swing.JList jLiEventosInvitado;
    private javax.swing.JList jLiEventosLista;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTEmail;
    private javax.swing.JTextField jTNombre;
    private javax.swing.JTextField jTTelefono;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

    /**
     * Método que carga todos los datos del formulario
     */
    public void cargarDatos() {
        jTNombre.setText(padre.miContacto.getNombre());
        jTEmail.setText(padre.miContacto.getEmail());
        jTTelefono.setText(padre.miContacto.getTelefono());
        jContra.setText(padre.miContacto.getContrasenya());

        cargarListaEventos();

        cargarListaAmigos();

        cargarListaEventosInvitado();

        cargarComboBoxAmigos();
    }

    /**
     * Método que limpia todo el formulario, se ejecuta al darle a Agenda de
     * eventos > Desconectar
     */
    public void desconectar() {
        jTEmail.setEditable(false);
        jTNombre.setEditable(false);
        jTTelefono.setEditable(false);
        jContra.setEditable(false);

        jBUsuarioModificar.setEnabled(true);
        jBGuardarUsuario.setEnabled(false);

        jLiEventosLista.removeAll();
        jLiContactoLista.removeAll();
        jCbContactoAmigoNuevo.removeAll();
    }

    /**
     * Método que carga la lista de eventos del usuario
     */
    public void cargarListaEventos() {
        // Lista de eventos propios - JLits
        DefaultListModel modelEventos = new DefaultListModel();

        for (Evento e : padre.listaEventos) {
            if (e.getIdcreador().getId() == padre.miContacto.getId()) {
                if (e.getFechainicio().after(new Date())) {
                    modelEventos.addElement(e);
                } else if (e.getFechafin().after(new Date())) {
                    modelEventos.addElement(e);
                }
            }
        }
        jLiEventosLista.setModel(modelEventos);
    }

    /**
     * Método que carga la lista de eventos a los que estoy invitado
     */
    public void cargarListaEventosInvitado() {
        // Lista de eventos a los que estoy invitado - JLits
        DefaultListModel modelEventos = new DefaultListModel();

        for (Invitar inv : padre.miContacto.getInvitarCollection()) {
            for (Evento e : padre.listaEventos) {
                if (e.getId() == inv.getIdevento().getId()) {
                    if (e.getFechainicio().after(new Date())) {
                        modelEventos.addElement(e);
                    } else if (e.getFechafin().after(new Date())) {
                        modelEventos.addElement(e);
                    }
                }
            }
        }
        jLiEventosInvitado.setModel(modelEventos);

    }

    /**
     * Método que carga la lista de amigos del contacto
     */
    private void cargarListaAmigos() {
        // Lista de amigos - JList
        jLiContactoLista.removeAll();
        DefaultListModel modelAmigos = new DefaultListModel();

        // Se podría usar la NamedQuery que hemos creado, pero así hay variedad...
        for (Seramigo sa : padre.listaAmigos) {
            if (sa.getIdamigo1().getId() == padre.miContacto.getId()) {
                modelAmigos.addElement(sa.getIdamigo2());
            } else if (sa.getIdamigo2().getId() == padre.miContacto.getId()) {
                modelAmigos.addElement(sa.getIdamigo1());
            }
        }
        jLiContactoLista.setModel(modelAmigos);
    }

    /**
     * Método que carga el combo box de amigos para añadir
     */
    private void cargarComboBoxAmigos() {
        // ComboBox de amigos - JComboBox
        jCbContactoAmigoNuevo.removeAll();
        DefaultComboBoxModel modelComboAmigos = new DefaultComboBoxModel();

        List<Seramigo> results = padre.em.createNamedQuery("Seramigo.findFriends", Seramigo.class)
                .setParameter("id", padre.miContacto).getResultList();

        for (Contacto c : padre.listaContactos) {
            boolean encontrado = false;
            if (c.getId() != padre.miContacto.getId()) {
                for (Seramigo sa : results) {
                    if (sa.getIdamigo1().getId() == c.getId()) {
                        encontrado = true;
                    } else if (sa.getIdamigo2().getId() == c.getId()) {
                        encontrado = true;
                    }
                }
                if (!encontrado) {
                    modelComboAmigos.addElement(c);
                }
            }
        }

        jCbContactoAmigoNuevo.setModel(modelComboAmigos);
    }
}
